<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('挤奶')"/>
    <th:block th:include="include :: select2-css"/>
    <style>
        .cow-code{
            color: #0d8ddb;
            display: inline-block;
            width: 80px;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ncWorkNotice-milk" th:object="${milk}">

        <div class="form-group">
            <input name="workNoticeId" id="workNoticeId"  th:field="*{workNoticeId}" type="hidden"  />
            <!--			<label class="col-sm-3 control-label">耳号</label>-->
            <div class="col-sm-12" >
               <!-- <tr th:each="user:${ncCowsFiles}">
                    <label class="col-sm-3 control-label">耳号
                        <td th:text="${user.cowCode}"></td>
                    </label>
                    <input class="form-control" type="hidden" name="cowId" id="cowId" th:value="${user.cowCode}"/>
                    <input class="form-control" type="text"  name="milkAmount" id="milkAmount"
                           placeholder="产奶量(kg)"/>
                </tr>-->
                <!--<input class="form-control" type="text" name="cowCode" id="cowCode" />-->
            </div>
        </div>
    </form>
    <div>
        <div class="select-list">
            <ul class="cows" style="text-align: center">
                <!--<li>
                    耳号1：<input type="text" name="piciCode"/>
                </li>-->
            </ul>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    function submitHandler() {
        /*if ($.validate.form()) {
            $.operate.save(ctx + "system/ncWorkNotice/milk", $('#form-ncWorkNotice-milk').serialize());
        }*/
        postCows();
    }

    getCows();
    /*表单确认*/
    function getCows() {
        var url = ctx + 'system/ncCowsFiles/list'
        myPost(url, {},
            function (data) {
                $('.cows').html('');
                if (data.code == 0) {
                    $(data.rows).each(function (i, e) {
                        var str = '<li> <span style="width: 100px; display: inline-block">耳号 ' + e.cowCode + "："+'</span> &nbsp;<input style="width: 70px" type="number" name="' + e.cowId + '" step="0.1"/>（kg） </li>'
                        $('.cows').append(str)
                    });
                } else {
                    layer.msg(data.msg);
                }
            }, function (e) {
                layer.msg("确认失败!");
            })


    }
    /*表单确认*/
    function postCows() {

         var data = [];
         $('.cows').find('input').each(function (i,e) {
               data.push({id:$(e).attr('name'),value:$(e).val()})

         });
         console.log(data)


        var workNoticeId = $("#workNoticeId").val()     /*{workNoticeId:workNoticeId},*/
        var url = ctx + 'system/ncWorkNotice/milk'
        myPost(url, {milks:data,workNoticeId:workNoticeId},
            function (data) {
                if (data.code == 0) {
                   layer.msg("成功")
                    reload()
                } else {
                    layer.msg(data.msg);
                }

            }, function (e) {
                layer.msg("确认失败!");
            })


    }

    function reload() {
        parent.window.close();

        parent.window.location.reload();
    }



</script>
</body>

</html>
